/**
 * 
 */
package com.baihui.taobao.quartz.jobs;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 * @author dev
 *
 */
public abstract class BaiHuiImportJob implements Job {
	
	/**
	 * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
	 */
	public void execute(JobExecutionContext context) throws JobExecutionException {
		String sign=context.getJobDetail().getJobDataMap().getString("sign");
		String contextPath=context.getJobDetail().getJobDataMap().getString("contextPath");
		String requestUrl=contextPath + this.getRequestUrl(context) + "&SIGN=" + sign;
		String userID=context.getJobDetail().getJobDataMap().getString("userID");

		URL url=null;
		URLConnection urlConnection=null;
		StringBuffer document = new StringBuffer();
		try {
			url=new URL(requestUrl);
			urlConnection=url.openConnection();
			urlConnection.connect();
			BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
	        String line = null;
	        while ((line = reader.readLine()) != null)
	        	document.append(line + "\n");
	        reader.close();

			Date endTime=new Date(System.currentTimeMillis());

		} catch (Exception e) {
			Date time=new Date(System.currentTimeMillis());
			
			e.printStackTrace();
		}
		finally{
			
		}
	}

	/**
	 * 获取HTTP服务URL
	 */
	protected String getRequestUrl(JobExecutionContext context){
		return null;
	}
	
	/**
	 * 导入任务开始提示
	 */
	protected void startTaskInfo(){
		
	}
	
	/**
	 * 导入结果提示信息
	 */
	protected void endTaskInfo(){
		
	}
	
}
